# from playwright.sync_api import sync_playwright, Request, Response, APIRequestContext
#
# class PlaywrightRequestContext:
#     def __init__(self, playwright: sync_playwright):
#         self.playwright = playwright
#         self.request_context = None
#
#     def create_context(self, base_url=None, user_agent=None, extra_http_headers=None):
#         options = {
#             'base_url': base_url,
#             'user_agent': user_agent,
#             'extra_http_headers': extra_http_headers
#         }
#         self.request_context = self.playwright.request.new_context(**options)
#
#     def get(self, url, params=None, headers=None) -> Response:
#         if self.request_context:
#             options = {'params': params, 'headers': headers}
#             response = self.request_context.get(url=url, **options)
#             return response
#
#     def post(self, url, data=None, headers=None) -> Response:
#         if self.request_context:
#             options = {'data': data, 'headers': headers}
#             response = self.request_context.post(url=url, **options)
#             return response
#     #
#     # def close(self):
#     #     if self.request_context:
#     #         self.request_context.close()
#
# # 示例用法
# with sync_playwright() as playwright:
#     request_context = PlaywrightRequestContext(playwright)
#     request_context.create_context(base_url='http://www.baidu.com', user_agent='Mozilla/5.0', extra_http_headers={'Authorization': 'Bearer token'})
#     response = request_context.get('/')
#     print(response.text)
#     # request_context.close()